import 'package:flutter/material.dart';

import 'package:get/get.dart';

import '../../../const.dart';
import '../controllers/other_profile_controller.dart';

class OtherProfileView extends GetView<OtherProfileController> {
  GestureDetector buildInfoTile(String title, String? content, Function callback) {
    return GestureDetector(
      onTap: () {
        callback();
      },
      child: Padding(
        padding: const EdgeInsets.only(top: 5, bottom: 6),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: TextStyle(color: Colors.grey),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                if(content == null || content == '')
                  Text('空')
                else
                  Text(content),
                Icon(
                  Icons.arrow_right,
                  color: Colors.grey,
                )
              ],
            )
          ],
        ),
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Obx(()=>Scaffold(
        appBar: AppBar(),
        body:  Container(
          color: bgColor,
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Row(
                children: [
                  Padding(
                    padding: const EdgeInsets.all(10),
                    child: ClipRRect(
                      borderRadius: BorderRadius.circular(13),
                      child:
                      controller.userInfo.value.avatar == null || controller.userInfo.value.avatar == ""? null
                          :Image.network(
                        controller.userInfo.value.avatar as String,
                        width: 106,
                      ),
                    ),
                  ),
                  Padding(
                    padding: const EdgeInsets.all(20.0),
                    child: Text(
                      controller.userInfo.value.nickname?? "nickname",
                      style: TextStyle(
                          fontWeight: FontWeight.w500, fontSize: 22),
                    ),
                  )
                ],
              ),
              controller.userInfo.value.id == null ? Container() :SizedBox(
                width: Get.width * .94,
                child: Card(
                  shape: RoundedRectangleBorder(
                      borderRadius: BorderRadius.circular(12)),
                  elevation: 2,
                  child: Padding(
                    padding: const EdgeInsets.all(15.0),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        buildInfoTile('账号', controller.userInfo.value.id.toString(), () {}),
                        buildInfoTile('性别', controller.userInfo.value.gender!? '男':'女', () {}),
                        buildInfoTile('生日', controller.userInfo.value.birthday, () {}),
                        buildInfoTile('个人签名', controller.userInfo.value.intro, () {}),
                      ],
                    ),
                  ),
                ),
              ),
            ],
          ),
        )
    ));
  }
}
